//
//  PlanRunVC.m
//  DefendHealth
//
//  Created by 吾诺瀚卓 on 17/3/7.
//  Copyright © 2017年 iMacOne. All rights reserved.
//

#import "PlanRunVC.h"
#import "PlanRunCell.h"
#import "DrillMessageVC.h"
@interface PlanRunVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView *tableView;

@end

@implementation PlanRunVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.TitleNav.text=@"计划跑";
    
    [self.view addSubview:self.tableView];
    self.tableView.tableHeaderView = [self headerView];
}

-(UITableView *)tableView{
    
    if (!_tableView) {
        
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, k_NavigationHeight, kScreenWidth, kScreenHeight-k_NavigationHeight) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = kWhiteColor;
        [_tableView registerClass:[PlanRunCell class] forCellReuseIdentifier:@"planRubCell"];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}
#pragma mark-tableView协议方法

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    PlanRunCell *cell = [tableView dequeueReusableCellWithIdentifier:@"planRubCell" forIndexPath:indexPath];
    cell.backgroundColor = kBlackColor;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.navigationController pushViewController:[DrillMessageVC new] animated:YES];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 175.0f;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 44.0f;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01f;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [self mostItems];
}

-(UIView *)mostItems{
    UIView * HeadView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 44)];
    HeadView.backgroundColor = kWhiteColor;
    
    UILabel * lefTitL = [ReduceCode creatLabelWithFrame:CGRectMake(10, 0, 80, 14) title:@"全部计划" titleColor:UIColorFromRGB(0x333333) font:14 textAlignment:NSTextAlignmentLeft];
    lefTitL.centerY = HeadView.centerY;
    
    [HeadView addSubview:lefTitL];
    
    UILabel * rigTitL = [ReduceCode creatLabelWithFrame:CGRectMake(kMaxX(HeadView.frame)-200, 0, 190, 14) title:@"您还可以选择其他计划" titleColor:UIColorFromRGB(0x999999) font:14 textAlignment:NSTextAlignmentRight];
    rigTitL.centerY = HeadView.centerY;
    [HeadView addSubview:rigTitL];
    return HeadView;
}

- (UIView *)headerView {
    
    self.TitleNav.textColor = UIColorFromRGB(0x888888);
    [self.leftbutton setImage:IMAGE(@"nav_icon_back") forState:UIControlStateNormal];
    
    [self.rigltbutton setImage:IMAGE(@"nav_icon_more") forState:UIControlStateNormal];
    
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, k_NavigationHeight, kScreenWidth, 275)];
    [ToolUtil createLine:0 superView:headerView lift:0 width:kScreenWidth hight:2 color:K_LineColor];
    UIImageView *housekeepIV = [ReduceCode creatImageVeiwWithFrame:CGRectMake(20, 15, 50, 50) imageName:@"Head_portrait" isCorner:YES];
    [headerView addSubview:housekeepIV];
    
    UILabel *titNameL = [ReduceCode creatLabelWithFrame:CGRectMake(kMaxX(housekeepIV.frame)+10, 25, 120, 30) title:@"Y管家推荐计划" titleColor:UIColorFromRGB(0x333333) font:16 textAlignment:NSTextAlignmentLeft];
    [headerView addSubview:titNameL];
    
    UILabel *subtitNameL = [ReduceCode creatLabelWithFrame:CGRectMake(kMaxX(headerView.frame)-200, 25, 180, 30) title:@"根据您的身体数据推荐" titleColor:UIColorFromRGB(0x999999) font:14 textAlignment:NSTextAlignmentRight];
    [headerView addSubview:subtitNameL];
    
    UIImageView *bgImageView = [ReduceCode creatImageVeiwWithFrame:CGRectMake(0, 54, kScreenWidth, 221) imageName:@"组-1" isCorner:NO];
    [headerView addSubview:bgImageView];
    
    [headerView insertSubview:bgImageView belowSubview:housekeepIV];
    
    UILabel *bigTitNameL = [ReduceCode creatLabelWithFrame:CGRectMake(20,kMaxY(titNameL.frame)+80, 150, 50) title:@"改善体制" titleColor:UIColorFromRGB(0xffffff) font:35 textAlignment:NSTextAlignmentLeft];
    [headerView addSubview:bigTitNameL];
    
    UILabel *followTitNameL = [ReduceCode creatLabelWithFrame:CGRectMake(20,kMaxY(bigTitNameL.frame)+5, 150, 30) title:@"7天5公里快步走" titleColor:UIColorFromRGB(0xffffff) font:17 textAlignment:NSTextAlignmentLeft];
    [headerView addSubview:followTitNameL];
    
    UILabel *nanDuL = [ReduceCode creatLabelWithFrame:CGRectMake(20, kMaxY(followTitNameL.frame)+20, 30, 20) title:@"难度" titleColor:UIColorFromRGB(0xffffff) font:14 textAlignment:NSTextAlignmentLeft];
    [headerView addSubview:nanDuL];
    
//    UIImageView *img = [ReduceCode creatImageVeiwWithFrame:CGRectMake(kMaxX(nanDuL.frame)+1, kMaxY(followTitNameL.frame)+20, 100, 20) imageName:@"yellow3" isCorner:NO];
//    [headerView addSubview:img];
    
    UIImageView *image = nil;
    for (int i = 0; i<5; i++) {
        image = [ReduceCode creatImageVeiwWithFrame:CGRectMake(kMaxX(nanDuL.frame)+i*(20+1), kMaxY(followTitNameL.frame)+22, 15, 15) imageName:@"diffcult_grey" isCorner:NO];
        [headerView addSubview:image];
    }
    for (int i = 0; i<2; i++) {
        UIImageView *images = [ReduceCode creatImageVeiwWithFrame:CGRectMake(kMaxX(nanDuL.frame)+i*(20+1), kMaxY(followTitNameL.frame)+22, 15, 15) imageName:@"diffcult" isCorner:NO];
        [headerView addSubview:images];
    }
    
    
    
    UILabel *numL = [ReduceCode creatLabelWithFrame:CGRectMake(kMaxX(image.frame)+1, kMaxY(followTitNameL.frame)+20, 120, 20) title:@"| 10000人已经参加" titleColor:UIColorFromRGB(0xffffff) font:14 textAlignment:NSTextAlignmentLeft];
    [headerView addSubview:numL];
    
    UIButton *energyVBut = [UIButton creatBtnWithFrame:CGRectMake(kMaxX(headerView.frame)-90, kMaxY(subtitNameL.frame)+185, 70, 22) btnTitle:nil btnTitleColor:nil btnTitleFont:0 btnTagPrice:0 btnSetImage:IMAGE(@"plan") btnBackgroundColor:nil isCorner:NO action:^(UIButton *button) {
        [self.navigationController pushViewController:[DrillMessageVC new] animated:YES];
    }];
  
    energyVBut.layer.cornerRadius = 10;
    energyVBut.clipsToBounds = YES;
    [headerView addSubview:energyVBut];
    
    return headerView;
}

-(void)leftEvents{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
